package com.sikaryofficial.backend.controller.information;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.backend.annotation.Repeat;
import com.sikaryofficial.backend.domain.dto.req.information.ArticleEvaluateListReq;
import com.sikaryofficial.backend.domain.dto.req.information.ArticleEvaluateReq;
import com.sikaryofficial.backend.domain.dto.resp.information.ArticleEvaluateDTO;
import com.sikaryofficial.backend.manager.information.ArticleEvaluateManager;
import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文章评价Controller
 *
 * @author qinjinyuan
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/article/evaluate")
@Api(tags = "资讯-文章评价")
public class ArticleEvaluateController extends BaseController {
    @Autowired
    private ArticleEvaluateManager evaluateManager;

    /**
     * 查询文章评价列表
     * 需要根据回复
     *
     */
    @PostMapping("/listPage")
    @ApiOperation("文章评价分页列表")
    @Repeat
    public PageResult<ArticleEvaluateDTO> listPage(@Validated @RequestBody ArticleEvaluateListReq req) {
        IPage<ArticleEvaluateDTO> page = evaluateManager.listPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

    /**
     * 获取文章评价详细信息
     */
    @GetMapping(value = "/{articleEvaluateId}")
    @ApiOperation("获取文章评价详细信息")
    public R<ArticleEvaluateDTO> getInfo(@PathVariable("articleEvaluateId") Long articleEvaluateId) {
        return R.ok(evaluateManager.getInfo(articleEvaluateId));
    }

    /**
     * 新增文章评价
     */
    @PostMapping("/add")
    @ApiOperation("新增文章评价")
    @Repeat
    public R<ArticleEvaluateDTO> save(@Validated @RequestBody ArticleEvaluateReq req) {
        return R.ok(evaluateManager.save(req));
    }
}
